package com.zihuop.server.service;


import android.os.RemoteCallbackList;
import android.os.RemoteException;
import android.util.Log;

import com.zihuop.server.IOperationListener;
import com.zihuop.server.IProcessInfo;
import com.zihuop.server.Test;

class IProcessInfoImpl extends IProcessInfo.Stub {
    private static final String TAG = IProcessInfoImpl.class.getSimpleName();
    //声明
    private RemoteCallbackList<IOperationListener> callbackList;

    public IProcessInfoImpl() {
        this.callbackList = new RemoteCallbackList<>();
    }

    @Override
    public void operation(Test test) throws RemoteException {
        //在操作 RemoteCallbackList 前，必须先调用其 beginBroadcast 方法
        //此外，beginBroadcast 必须和 finishBroadcast配套使用
        int count = callbackList.beginBroadcast();
        for (int i = 0; i < count; i++) {
            IOperationListener listener = callbackList.getBroadcastItem(i);
            if (listener != null) {
                listener.onOperation(new Test(100, "999"));
            }
        }
        callbackList.finishBroadcast();
        Log.e(TAG, "计算结束");
    }

    @Override
    public void registerListener(IOperationListener listener) {
        callbackList.register(listener);
    }

    @Override
    public void unregisterListener(IOperationListener listener) {
        callbackList.unregister(listener);
    }
}
